package com.sikaryofficial.backend.constant;

import com.sikaryofficial.common.core.constant.PointRuleConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;


/**
 * @author : qinjinyuan
 * @desc : 用户行为类型
 * @date : 2023/11/09 11:12
 */
@AllArgsConstructor
@Getter
public enum UserActionTypeEnum {
    /**
     * 行为类型:点赞
     */
    LIKES(1, "点赞", UserActionConstant.ACTION_TYPE_LIKES, new Integer[]{6, 8, 9, 21, 22, 23}),
    /**
     * 收藏
     */
    COLLECTIONS(2, "收藏", UserActionConstant.ACTION_TYPE_COLLECTIONS, new Integer[]{10, 3, 15, 24}),
    /**
     * 转发
     */
    FORWARD(3, "转发", UserActionConstant.ACTION_TYPE_FORWARD, new Integer[]{5, 11, 16, 25});

    private final Integer code;
    private final String name;
    private final String serviceName;

    private final Integer[] businessTypes;

    public static UserActionTypeEnum getByCode(Integer code) {
        return Arrays.stream(UserActionTypeEnum.values()).filter(pointRuleEnum -> Objects.nonNull(code) && pointRuleEnum.getCode().equals(code)).findFirst().orElse(null);
    }

    public static String getServicePrefixCode(Integer code, Integer businessType) {
        UserActionTypeEnum userActionTypeEnum = getByCode(code);
        if (null == userActionTypeEnum) {
            return null;
        }
        if (LIKES == userActionTypeEnum && MyStatisticsTypeEnum.LIKES_ARTICLE.getBusinessType().equals(businessType)) {
            return PointRuleConstant.ARTICLE_LIKE;
        }
        return null;
    }

    public static String getReceivedServicePrefixCode(Integer code, Integer businessType) {
        UserActionTypeEnum userActionTypeEnum = getByCode(code);
        if (null == userActionTypeEnum) {
            return null;
        }
        if (LIKES == userActionTypeEnum && MyStatisticsTypeEnum.LIKES_ARTICLE.getBusinessType().equals(businessType)) {
            return PointRuleConstant.ARTICLE_RECEIVED_LIKE;
        }
        return null;
    }

}
